<?php $this->assign("title", "Agregar Ruta"); ?>
<?php
	$this->start('script');
		echo $this->Html->script('http://js.cit.api.here.com/se/2.5.4/jsl.js?with=all');
		echo $this->Html->script('Rutas/maparutas2.min');
	$this->end(); 

	$this->Js->set('paradas', $paradas);

	$names=array();
	foreach ($paradas as $key =>$cell){
		foreach ($cell as $key=>$value){
			$names[	$value['id_parada']	]=$value['nombre_parada'];
		}
	}
?>
<h2>Agregar Ruta</h2>
<div class="cols-display">
	<div class="cols2">
		<?php 
			echo $this->Form->create('Ruta');
			echo $this->Form->input('nombre_ruta');
			echo $this->Form->input('descripcion_ruta', array('rows' => '3'));
		?>
		<fieldset id="0">
			<legend>Parada Origen</legend>
			<?php 
				echo $this->Form->input("RutaParada.0.id_parada", array("label" => "Parada", "type" => "select", 'empty' => 'Elija...', "disabled" => "", "options" => $names, "required" => "required"));
				echo $this->Form->hidden("RutaParada.0.orden_ruta", array("value"=>"1", "required" => "required"));
				echo $this->Form->hidden("RutaParada.0.tipo_parada", array("value"=>"origen", "required" => "required"));

				echo $this->Form->hidden("RutaParada.0.latitud", array("value"=>"", "required" => "required",));
				echo $this->Form->hidden("RutaParada.0.longitud", array("value"=>"", "required" => "required"));

			?>
		</fieldset>
		<fieldset id="2">
			<legend>Parada Destino</legend>
			<?php 
				echo $this->Form->input("RutaParada.1.id_parada", array("label" => "Parada", "type" => "select", 'empty' => 'Elija...', "disabled" => "", "options" => $names, "required" => "required"));
				echo $this->Form->hidden("RutaParada.1.orden_ruta", array("value"=>isset($this->request->data['RutaParada'])?(sizeof($this->request->data['RutaParada'])):("2"), "required" => "required","id"=>"ordenParadaDestino"));
				echo $this->Form->hidden("RutaParada.1.tipo_parada", array("value"=>"destino", "required" => "required"));

				echo $this->Form->hidden("RutaParada.1.latitud", array("value"=>"", "required" => "required",));
				echo $this->Form->hidden("RutaParada.1.longitud", array("value"=>"", "required" => "required"));
			?>
		</fieldset>
		<fieldset id="3">
			<legend>Paradas Intermedias</legend>
			<div id="contenedor_paradas_intermedias">
			<?php
				if (!empty($this->request->data)){
					foreach ($this->request->data['RutaParada'] as $i => $detalles) {
						if ($i == 0 || $i == 1) {
							continue;
						}
						echo $this->Form->input("RutaParada." . $i . ".id_parada", array("label" => "Parada", "type" => "select", 'empty' => 'Elija...', "disabled" => "", "options" => $names, "required" => "required"));
						echo $this->Form->hidden("RutaParada." . $i . ".orden_ruta", array("value"=>($i), "required" => "required","id"=>"ordenParadaDestino"));
						echo $this->Form->hidden("RutaParada." . $i . ".tipo_parada", array("value"=>"intermedia", "required" => "required"));

						echo $this->Form->hidden("RutaParada." . $i . ".latitud", array("value"=>"", "required" => "required",));
						echo $this->Form->hidden("RutaParada." . $i . ".longitud", array("value"=>"", "required" => "required"));

					}
				}
			?>
			</div>
			<?php 
				echo $this->Form->button("Agregar Parada Intermedia", array("type" => "button", "id" => "agregarParadaIntermedia"));
			?>
		</fieldset>
		<div id="waypointsAyuda"></div>
		<?php
			echo $this->Form->end('Guardar Ruta');
		?>
	</div>
	<div class="cols2">
		<div id="map"></div>
	</div>
</div>
